#include <iostream>
using namespace std;

const int N = 2e5 + 10;

typedef long long LL;

int n;
LL f[N],minf = 0,maxsu = -1e20;

int main(){
	cin >> n;
	for(int i = 1;i <= n;i++){
		LL x;
		cin >> x;
		f[i] = f[i - 1] + x;
		maxsu = max(maxsu,f[i] - minf);
		minf = min(minf,f[i]);
	}
	cout << maxsu << endl;
	return 0;
}
